﻿using System;
namespace Colors.Xroad.Eu.Messages {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SettingsResponse", Namespace="http://colors.x-road.eu/", Target=typeof(SettingsResponse))]
    public class SettingsResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected SettingsResponse clazz;
        
        public SettingsResponseSerializer(SettingsResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Settings");
            if (clazz.Settings!=null) {
                global::Xtee.Core.SerializationMetadata metaSettings = this.GetMetaData(clazz.Settings);
                if (ShouldWriteTypeAttribute(typeof(global::Colors.Xroad.Eu.Settings), clazz.Settings.GetType())) {
                    Writer.WriteTypeAttribute(metaSettings.TypeQualifiedName.Namespace, metaSettings.TypeQualifiedName.Name);
                }
                var settingsSerializer = metaSettings.NewSerializer(clazz.Settings);
                settingsSerializer.WriteXmlAttributes(Writer);
                settingsSerializer.WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Settings");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Settings") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>SettingsResponse>Settings");
                }
                global::Xtee.Core.SerializationMetadata metaSettings = this.GetMetaData<global::Colors.Xroad.Eu.Settings>(Reader, "Settings", "http://colors.x-road.eu/");
                clazz.Settings = metaSettings.NewEntity<global::Colors.Xroad.Eu.Settings>();
                if ((Reader.IsEmptyElement == false)) {
                    var settingsSerializer = metaSettings.NewSerializer(clazz.Settings);
                    settingsSerializer.ReadXmlAttributes(Reader);
                    Reader.ReadStartElement("Settings");
                    settingsSerializer.ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>SettingsResponse>Settings", Reader.LocalName);
            }
        }
    }
}
